home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1992 June: ROMin Holiday / ADC Developer CD (1992-06) (''ROMin Holiday'')_iso / Developer Connection - 06-1992.iso / Development Platforms / Apple II / Apple II Sample Code / MPW IIGS SC / SC.001.Shell / Asm Shell / Shell.aii next >
Encoding:
Text File  |  1990-06-24  |  18.0 KB  |  765 lines  |  [TEXT/MPS ]

  1. *
  2. *   Standard Application Shell  - Assembly Version
  3. *             Developer Technical Support
  4. *
  5. *     v3.0    Mensch & Rollin, Deatherage & Luther
  6. *
  7. *    Developer Technical Support Apple II Sample Code
  8. *
  9. *    Copyright (c) Apple Computer, Inc. 1988-1990
  10. *               All Rights Reserved.
  11. *
  12. *   ------------------------------------------------------
  13. *
  14. *   This program and its derivatives are licensed only for
  15. *   use on Apple computers.
  16. *
  17. *   Works based on this program must contain and
  18. *   conspicuously display this notice.
  19. *
  20. *   This software is provided for your evaluation and to
  21. *   assist you in developing software for the Apple IIGS
  22. *   computer.
  23. *
  24. *   DISCLAIMER OF WARRANTY
  25. *
  26. *   THE SOFTWARE IS PROVIDED "AS IS" WITHOUT
  27. *   WARRANTY OF ANY KIND, EITHER EXPRESS OR IMPLIED,
  28. *   WITH RESPECT TO ITS MERCHANTABILITY OR ITS FITNESS
  29. *   FOR ANY PARTICULAR PURPOSE.  THE ENTIRE RISK AS TO
  30. *   THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH
  31. *   YOU.  SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU (AND
  32. *   NOT APPLE OR AN APPLE AUTHORIZED REPRESENTATIVE)
  33. *   ASSUME THE ENTIRE COST OF ALL NECESSARY SERVICING,
  34. *   REPAIR OR CORRECTION.
  35. *
  36. *   Apple does not warrant that the functions
  37. *   contained in the Software will meet your requirements
  38. *   or that the operation of the Software will be
  39. *   uninterrupted or error free or that defects in the
  40. *   Software will be corrected.
  41. *
  42. *   SOME STATES DO NOT ALLOW THE EXCLUSION
  43. *   OF IMPLIED WARRANTIES, SO THE ABOVE EXCLUSION MAY
  44. *   NOT APPLY TO YOU.  THIS WARRANTY GIVES YOU SPECIFIC
  45. *   LEGAL RIGHTS AND YOU MAY ALSO HAVE OTHER RIGHTS
  46. *   WHICH VARY FROM STATE TO STATE.
  47. *
  48.     EJECT
  49.     PRINT NOGEN,NOHDR
  50.  
  51.     STRING ASIS
  52.  
  53.     PRINT PUSH,OFF
  54.     INCLUDE 'E16.Types'
  55.     INCLUDE 'M16.Util'
  56.     INCLUDE 'M16.GSOS'
  57.     INCLUDE 'E16.GSOS'
  58.     INCLUDE 'M16.Locator'
  59.     INCLUDE 'E16.Locator'
  60.     INCLUDE 'M16.ADB'
  61.     INCLUDE 'E16.ADB'
  62.     INCLUDE 'M16.IntMath'
  63.     INCLUDE 'E16.IntMath'
  64.     INCLUDE 'M16.TextTool'
  65.     INCLUDE 'E16.TextTool'
  66.     INCLUDE 'M16.Memory'
  67.     INCLUDE 'E16.Memory'
  68.     INCLUDE 'M16.SANE'
  69.     INCLUDE 'E16.SANE'
  70.     INCLUDE 'M16.ACE'
  71.     INCLUDE 'E16.ACE'
  72.     INCLUDE 'M16.Resources'
  73.     INCLUDE 'E16.Resources'
  74.     INCLUDE 'M16.MiscTool'
  75.     INCLUDE 'E16.MiscTool'
  76.     INCLUDE 'M16.Scheduler'
  77.     INCLUDE 'E16.Scheduler'
  78.     INCLUDE 'M16.Loader'
  79.     INCLUDE 'E16.Loader'
  80.     INCLUDE 'M16.Quickdraw'
  81.     INCLUDE 'E16.Quickdraw'
  82.     INCLUDE 'M16.QDAux'
  83.     INCLUDE 'E16.QDAux'
  84.     INCLUDE 'M16.Event'
  85.     INCLUDE 'E16.Event'
  86.     INCLUDE 'M16.Control'
  87.     INCLUDE 'E16.Control'
  88.     INCLUDE 'M16.Window'
  89.     INCLUDE 'E16.Window'
  90.     INCLUDE 'M16.Menu'
  91.     INCLUDE 'E16.Menu'
  92.     INCLUDE 'M16.LineEdit'
  93.     INCLUDE 'E16.LineEdit'
  94.     INCLUDE 'M16.Dialog'
  95.     INCLUDE 'E16.Dialog'
  96.     INCLUDE 'M16.Sound'
  97.     INCLUDE 'E16.Sound'
  98.     INCLUDE 'M16.NoteSyn'
  99.     INCLUDE 'E16.NoteSyn'
  100.     INCLUDE 'M16.NoteSeq'
  101.     INCLUDE 'E16.NoteSeq'
  102.     INCLUDE 'M16.MIDI'
  103.     INCLUDE 'E16.MIDI'
  104.     INCLUDE 'M16.StdFile'
  105.     INCLUDE 'E16.StdFile'
  106.     INCLUDE 'M16.Scrap'
  107.     INCLUDE 'E16.Scrap'
  108.     INCLUDE 'M16.Desk'
  109.     INCLUDE 'E16.Desk'
  110.     INCLUDE 'M16.List'
  111.     INCLUDE 'E16.List'
  112.     INCLUDE 'M16.Font'
  113.     INCLUDE 'E16.Font'
  114.     INCLUDE 'M16.Print'
  115.     INCLUDE 'E16.Print'
  116.     INCLUDE 'M16.TextEdit'
  117.     INCLUDE 'E16.TextEdit'
  118.     INCLUDE 'M16.Video'
  119.     INCLUDE 'E16.Video'
  120.  
  121.     PRINT POP
  122.  
  123. *******************************************************************************
  124. *
  125. *    Equates used in this program.
  126. *
  127.  
  128. ; Offsets into direct page
  129. Deref    equ 0    ; for temporary dereferencing
  130.  
  131. ; menu item numbers for standard DA menu items
  132. UndoID    equ 250
  133. CutID    equ 251
  134. CopyID    equ 252
  135. PasteID    equ 253
  136. ClearID    equ 254
  137. CloseID    equ 255
  138.  
  139. ; application menu item numbers
  140. AboutID    equ $1101    ; 1st item of 1st menu of 1st menu bar
  141. QuitID    equ $1202    ; 2nd item of 2nd menu of 1st menu bar
  142.  
  143. ; application menu numbers
  144. AppleMenuID    equ $1100    ; 1st menu of 1st menu bar
  145. FileMenuID    equ $1200    ; 2nd menu of 1st menu bar
  146. EditMenuID    equ $1300    ; 3rd menu of 1st menu bar
  147.  
  148. ; resource ID numbers
  149. BaseResID    equ $00000000    ; start of resource ID numbers
  150. MenuBarOneRID    equ $00001000    ; resource ID of menu bar
  151.  
  152. MyTaskMask    equ $001FFFFF    ; Handle all events possible
  153.  
  154.     EJECT
  155. *******************************************************************************
  156. *
  157. main    PROC
  158. *
  159. * Description:    This is the main routine. It calls procedures to startup
  160. *    the tools, initialize application specific data, run the
  161. *    main eventLoop, close the application, and shutdown the
  162. *    tools.  Then it calls the GS/OS Quit command.
  163. *
  164. * Inputs:    NONE
  165. * Outputs:    NONE
  166. * External Refs:
  167.     import initTools
  168.     import initApp
  169.     import eventLoop
  170.     import closeApp
  171.     import closeTools
  172.     import QuitParms
  173. * Entry Points:    NONE
  174. *
  175.     jsr initTools    ; Initialize tools.
  176.     jsr initApp    ; Initialize application specific
  177.         ; stuff.
  178.  
  179.     jsr eventLoop    ; Do application stuff until user 
  180.         ; wants to do something else!
  181.     
  182.     jsr closeApp    ; ShutDown application specific things.
  183.     jsr closeTools    ; ShutDown the tools.
  184.  
  185.     _QuitGS QuitParms    ; and Quit
  186.     ENDP
  187.  
  188.     EJECT
  189. *******************************************************************************
  190. *
  191. Globals    Record
  192. *
  193. * Description:    Holder of all of our data.
  194. *
  195. * Inputs:    N/A
  196. * Outputs:    N/A
  197. * External Refs:    NONE
  198. * Entry Points:
  199.     export QuitParms    ; used by main
  200. *
  201.  
  202. ; Standard global variables here
  203. MyMemoryID    ds.B 2    ; Application's memory ID
  204. Done    ds.W 1    ; flag to show when to quit application
  205. ToolRecRef    ds.B 4    ; StartStopRec from StartUpTools
  206. WindowKind    ds.B 2    ; type of top window from GetWKind call
  207. MenuHeight    ds.B 2    ; Stored height of menu bar
  208. QuitParms    dc.W $00    ; pCount = 0
  209.  
  210. ; The following is the record that is used by TaskMaster to return
  211. ; events. It is similar to a regular event record, except that there are
  212. ; additional fields at the end. The first additional field is used to convey
  213. ; some TaskMaster specific data back to the application. The second additional
  214. ; field is called the TaskMask and is used to tell TaskMaster what situations
  215. ; to handle.  In this shell, we tell TaskMaster to handle everything by
  216. ; setting all currently defined bits to 1 (MyTaskMask) in the initApp
  217. ; routine.
  218.  
  219. MyEvent
  220. EventWhat    ds.B 2
  221. EventMessage    ds.B 4
  222. EventWhen    ds.B 4
  223. EventWhere    ds.B 4
  224. EventModifiers    ds.B 2
  225. TaskData    ds.B 4
  226. TaskMask    dc.L MyTaskMask
  227. LastClickTick    ds.B 4
  228. ClickCount    ds.B 2
  229. TaskData2    ds.B 4
  230. TaskData3    ds.B 4
  231. TaskData4    ds.B 4
  232. LastClickPtY    ds.B 2
  233. LastClickPtX    ds.B 2
  234.  
  235.     EndR
  236.  
  237.     EJECT
  238. *******************************************************************************
  239. *
  240. initTools    PROC
  241. *
  242. * Description:    Load and startup the tools needed. Errors are detected
  243. *    and fatalError is called if any occur.
  244. *
  245. * Inputs:    NONE
  246. * Outputs:    NONE
  247. * External Refs:
  248.     import fatalError
  249. * Entry Points:    NONE
  250. *
  251.     with Globals
  252.  
  253.     phk    ; save program bank register and
  254.     plb    ; load it as the data bank register
  255.  
  256.     _TLStartup    ; start up Tool Locator
  257.     bcc initMM
  258.     ldx #$1    ; if error, then set the error
  259.         ; reference number
  260.     jmp fatalError    ; and jump to fatal routine
  261.  
  262. initMM    pha    ; space for result
  263.     _MMStartup    ; start up memory manager
  264.     bcc getMMID
  265.     ldx #$2    ; if error, then set the error
  266.         ; reference number
  267.     jmp fatalError    ; and jump to fatal routine
  268.  
  269. getMMID    PullWord MyMemoryID    ; Get the Memory ID returned
  270.  
  271.     PushLong #$0    ; space for the Record returned
  272.     PushWord MyMemoryID    ; our User ID
  273.     PushWord #refIsResource ; the StartStopRec is a resource
  274.     PushLong #BaseResID+1 ; the actual resource ID
  275.     _StartUpTools
  276.     bcc getToolRecRef
  277.     ldx #$3    ; if error, then set the error
  278.         ; reference number
  279.     jmp fatalError    ; and jump to fatal routine
  280.  
  281. getToolRecRef    PullLong ToolRecRef ; Store the reference returned
  282.  
  283.     rts
  284.     ENDP
  285.  
  286.     EJECT
  287. *******************************************************************************
  288. *
  289. fatalError    PROC
  290. *
  291. * Description:    Routine that is called whenever an error is detected
  292. *    that can not be recovered from. This routine prints an
  293. *    error message, waits for a keypress, then quits back
  294. *    to whoever started this application up!
  295. *
  296. * Inputs:    A = Error number
  297. *    X = the reference number that tells you where in
  298. *    initTools the error happened.
  299. * Outputs:    NONE (program exits)
  300. * External Refs:
  301.     import closeTools
  302. * Entry Points:    NONE
  303. *
  304.     with Globals
  305.  
  306.     phx    ; save the "where" reference number
  307.     
  308.     pha    ; Push the error code
  309.     PushLong #errNumStr    ; Address of storage area
  310.     PushWord #$4    ; Length of string
  311.     _Int2Hex
  312.  
  313.     pla    ; get the "where" reference number
  314.     pha    ; and push it
  315.     PushLong #errWhereStr ; Address of storage area
  316.     PushWord #$4    ; Length of string
  317.     _Int2Hex
  318.     
  319.     _GrafOff    ; If QD Started, shut off graphics
  320.  
  321.     PushLong #ErrStr    ; Write error message to the screen
  322.     _WriteCString
  323.     
  324.     _SysBeep    ; ring the bell
  325.  
  326.     pha    ; Space for result
  327.     PushWord #noEcho    ; No echo
  328.     _ReadChar    ; Wait for a key to be pressed
  329.     pla    ; Discard the key
  330.  
  331.     jsr closeTools    ; Shut down all the tools in case
  332.         ; any got started up
  333.  
  334.     _QuitGS QuitParms    ; Quit back to where we came from.
  335.  
  336. ; Quit can only fail with GS/OS busy, so we never come back from the quit call.
  337.     
  338. ErrStr    dc.B 'Fatal error $'
  339. ErrNumStr    dc.B 'xxxx has occured at '
  340. ErrWhereStr    dc.B 'xxxx. Press any key to exit:',0
  341.  
  342.     ENDP
  343.  
  344.     EJECT
  345. *******************************************************************************
  346. *
  347. initApp    PROC
  348. *
  349. * Description:    Perform any application specific initialization. For this
  350. *    app, we initialize the Done to false, set WindowKind to
  351. *    an application window kind, and initialize all of the
  352. *    menus.
  353. *
  354. *    You might use this procedure to create windows, initialize
  355. *    variables and allocate memory needed for the entire
  356. *    program.
  357. *
  358. * Inputs:    NONE
  359. * Outputs:    NONE
  360. * External Refs:    NONE
  361. * Entry Points:    NONE
  362. *
  363.     with Globals
  364.  
  365.     stz Done    ; we aren't done yet
  366.     stz WindowKind    ; window kind = application
  367.  
  368. ;
  369. ; create default system menu bar from a resource and make it the
  370. ; current menu bar
  371. ;
  372.     pha
  373.     pha    ; space for result
  374.     PushWord #refIsResource ; reference is resource
  375.     PushLong #MenuBarOneRID ; menu bar resource ID
  376.     PushLong #$0    ; system menu bar
  377.     _NewMenuBar2
  378.         
  379.     _SetSysBar    ; and this is the system bar
  380.     
  381.     PushLong #$0    ; zero means use the system menu bar
  382.     _SetMenuBar
  383.     
  384.     PushLong #$0    ; refresh the whole desktop
  385.     _RefreshDeskTop
  386.  
  387.     _InitCursor    ; normal arrow cursor
  388.  
  389.     PushWord #AppleMenuID ; Add NDA's
  390.     _FixAppleMenu
  391.  
  392.     pha    ; Call FixMenuBar to cause the menu
  393.     _FixMenuBar    ; Compute standard menu sizes
  394.     PullWord MenuHeight    ; and store the menu height for later
  395.  
  396.     _DrawMenuBar    ; Finally, draw it.
  397.  
  398.     rts
  399.     ENDP
  400.  
  401.     EJECT
  402. *******************************************************************************
  403. *
  404. eventLoop    PROC
  405. *
  406. * Description:    The Event Loop. Handle things until user selects Quit.
  407. *
  408. * Inputs:    NONE
  409. * Outputs:    NONE
  410. * External Refs:
  411.     import doMenu
  412.     import testTopWindow
  413. * Entry Points:    NONE
  414. *
  415.     with Globals
  416.  
  417.     jsr testTopWindow    ; test to see if top window is a DA
  418.     
  419.     pha    ; Push on space for TaskMaster result
  420.     PushWord #EveryEvent ; GetNextEvent mask
  421.     PushLong #MyEvent    ; Pointer to Event Record
  422.     _TaskMaster
  423.     pla    ; Get TaskMaster result
  424.     
  425. ; Now we have the task type
  426.  
  427.     ldx #endTaskTable-taskTable-4
  428. checkNextItem    cmp taskTable,x    ; are we handling this event?
  429.     beq doRoutine    ; yes, then call a routine
  430.     dex    ; no, then keep checking
  431.     dex
  432.     dex
  433.     dex
  434.     bpl checkNextItem    ; keep scanning table
  435.     
  436.     bra eventLoop    ; event not handled, so get another    
  437.     
  438. doRoutine    jsr (taskTable+2,x)    ; call the routine
  439.     
  440.     lda Done    ; Quit selected?
  441.     beq eventLoop    ; no - keep looping
  442.  
  443.     rts    ; yes- leave the program
  444.  
  445. ; With most of these events, we do nothing (in fact, most applications will
  446. ; never see some of these events). You should cut or comment out the lines
  447. ; for events your application does not use out of this table (as we've done).
  448. ; Any of these events your application does use should call a routine to
  449. ; handle the event.
  450.  
  451. taskTable
  452. ;    dc.W nullEvt,    doNullEvt
  453. ;    dc.W mouseDownEvt,     doMouseDownEvt
  454. ;    dc.W mouseUpEvt,    doMouseUpEvt
  455. ;    dc.W keyDownEvt,    doKeyDownEvt
  456. ;    dc.W autoKeyEvt,    doAutoKeyEvt
  457. ;    dc.W updateEvt,    doUpdateEvt
  458. ;    dc.W activateEvt,    doActivateEvt
  459. ;    dc.W switchEvt,    doSwitchEvt
  460. ;    dc.W deskAccEvt,    doDeskAccEvt
  461. ;    dc.W driverEvt,    doDriverEvt
  462. ;    dc.W app1Evt,    doApp1Evt
  463. ;    dc.W app2Evt,    doApp2Evt
  464. ;    dc.W app3Evt,    doApp3Evt
  465. ;    dc.W app4Evt,    doApp4Evt
  466. ;    dc.W wInDesk,    doWInDesk
  467.     dc.W wInMenuBar,    doMenu
  468. ;    dc.W wClickCalled,    doWClickCalled
  469. ;    dc.W wInContent,    doWInContent
  470. ;    dc.W wInDrag,    doWInDrag
  471. ;    dc.W wInGrow,    doWInGrow
  472. ;    dc.W wInGoAway,    doWInGoAway
  473. ;    dc.W wInZoom,    doWInZoom
  474. ;    dc.W wInInfo,    doWInInfo
  475.     dc.W wInSpecial,    doMenu
  476. ;    dc.W wInDeskItem,    doWInDeskItem
  477. ;    dc.W wInFrame,    doWInFrame
  478. ;    dc.W wInactMenu,    doWInactMenu
  479. ;    dc.W wClosedNDA,    doWClosedNDA
  480. ;    dc.W wCalledSysEdit,doWCalledSysEdit
  481. ;    dc.W wTrackZoom,    doWTrackZoom
  482. ;    dc.W wHitFrame,    doWHitFrame
  483. ;    dc.W wInControl,    doWInControl
  484. ;    dc.W wInControlMenu,doWInControlMenu
  485. endTaskTable    
  486.  
  487.     ENDP
  488.  
  489.     EJECT
  490. *******************************************************************************
  491. *
  492. closeApp    PROC
  493. *
  494. * Description:    Close down things. This disposes of all items and memory
  495. *    that we allocated. Usually undoes what was done in
  496. *    initApp.  We don't close our window since _WindShutDown
  497. *    does it for us.
  498. *
  499. * Inputs:    NONE
  500. * Outputs:    NONE
  501. * External Refs:    NONE
  502. * Entry Points:    NONE
  503. *
  504.     with Globals
  505.     
  506. ; do nothing in this shell
  507.  
  508.     rts
  509.     ENDP
  510.  
  511.     EJECT
  512. *******************************************************************************
  513. *
  514. closeTools    PROC
  515. *
  516. * Description:    Shut down the tools I started.
  517. *
  518. * Inputs:    NONE
  519. * Outputs:    NONE
  520. * External Refs:    NONE
  521. * Entry Points:    NONE
  522. *
  523.     with Globals
  524.  
  525.     PushWord #refIsHandle ; A handle (since StartUp returned it)
  526.     PushLong ToolRecRef ; The value returned by StartUpTools
  527.     _ShutDownTools
  528.     
  529.     PushWord MyMemoryID
  530.     _MMShutDown
  531.     _TLShutDown
  532.  
  533.     rts
  534.     ENDP
  535.  
  536.     EJECT
  537. *******************************************************************************
  538. *
  539. testTopWindow    PROC
  540. *
  541. * Description:    This routine is called on every NULL event. It checks the
  542. *    type of the top window, if it has changed from App window
  543. *    to system window or back, this routine will call
  544. *    doSysChange.
  545. *
  546. * Inputs:    NONE
  547. * Outputs:    NONE
  548. * External Refs:
  549.     import doSysChange
  550. * Entry Points:    NONE
  551. *
  552.     with Globals
  553.     
  554.     PushLong #$0    ; first get a pointer to the frontmost
  555.     _FrontWindow    ; window
  556.     PullLong Deref    ; store it in deref temporarily
  557.     
  558.     lda Deref    ; first test for a NIL pointer. If its
  559.     ora Deref+2    ; NIL then we do not have to do the 
  560.     beq checkKind    ; getWKind call
  561.     
  562.     PushWord #$0    ; if not a NIL pointer then get the
  563.     PushLong Deref    ; Kind of window
  564.     _getWKind
  565.     pla
  566.     
  567. checkKind    cmp WindowKind    ; Now test the window kind to see if it
  568.     beq noChange    ; has changed, if not then ignore it
  569.     
  570.     sta WindowKind    ; if the window kind has changed, then
  571.     jsr doSysChange    ; save the new value and change menus
  572.  
  573. noChange    rts
  574.     EndP
  575.  
  576.     EJECT
  577. *******************************************************************************
  578. *
  579. doSysChange    PROC
  580. *
  581. * Description:    Called by eventLoop when the upper most window
  582. *    has changed to or from a system window.
  583. *
  584. * Inputs:    <A> Bit 15 of WindowKind is 0 if top window is an
  585. *    application window, 1 if top window is a system window.
  586. * Outputs:    NONE
  587. * External Refs:    NONE
  588. * Entry Points:    NONE
  589. *
  590.     with Globals
  591.  
  592.     and #%1000000000000000
  593.     bpl SysDeact    ; if high bit clear then App Window
  594.  
  595. ; This routine enables the edit menu when a system window becomes active
  596.  
  597. SysActivate    PushWord #UndoID    ; its an activate event so go thru and
  598.     _EnableMItem    ; enable all the edit items and the
  599.     
  600.     PushWord #CutID    ; close Item
  601.     _EnableMItem
  602.     
  603.     PushWord #CopyID
  604.     _EnableMItem
  605.     
  606.     PushWord #PasteID
  607.     _EnableMItem
  608.     
  609.     PushWord #ClearID
  610.     _EnableMItem
  611.     
  612.     PushWord #CloseID
  613.     _EnableMItem
  614.     
  615. ; If your edit menu has items that are selectable when a DA is not front-most,
  616. ; remove the next six lines.
  617.     PushWord #enableMenu ; defined in E16.Menu
  618.     PushWord #EditMenuID
  619.     _SetMenuFlag
  620.     pea $0000    ; FALSE
  621.     PushWord #EditMenuID
  622.     _HiliteMenu
  623.     
  624.     rts
  625.  
  626. ; This routine disables the edit menu when an system window is not active
  627.  
  628. SysDeact    PushWord #UndoID    ; its an deactivate event so go thru 
  629.     _DisableMItem    ; and disable all the edit items and 
  630.     
  631.     PushWord #CutID    
  632.     _DisableMItem
  633.     
  634.     PushWord #CopyID
  635.     _DisableMItem
  636.     
  637.     PushWord #PasteID
  638.     _DisableMItem
  639.     
  640.     PushWord #ClearID
  641.     _DisableMItem
  642.  
  643.     PushWord #CloseID    ; the close Item
  644.     _DisableMItem
  645.  
  646. ; If your edit menu has items that are selectable when a DA is not front-most,
  647. ; remove the next six lines.
  648.     PushWord #disableMenu ; defined in E16.Menu
  649.     PushWord #EditMenuID
  650.     _SetMenuFlag
  651.     pea $0000    ; FALSE
  652.     PushWord #EditMenuID
  653.     _HiliteMenu
  654.     
  655.     rts
  656.     ENDP
  657.  
  658.     EJECT
  659. *******************************************************************************
  660. *
  661. doMenu    PROC
  662. *
  663. * Description:    This routine is called when TaskMaster returns a menu
  664. *    event. It takes the menu item that was hit and calls the
  665. *    proper routine, and then unhilites the menu when it is
  666. *    done. 
  667. *
  668. * Inputs:    TaskData holds menu item selected.
  669. * Outputs:    NONE
  670. * External Refs:
  671.     import doAbout
  672.     import doQuit
  673. * Entry Points:    NONE
  674. *
  675.     with Globals
  676.     
  677.     lda TaskData    ; get ID of selected menu item
  678.     
  679.     ldx #endMenuTable-menuTable-4
  680. checkNextItem    cmp menuTable,x
  681.     beq doRoutine
  682.     dex
  683.     dex
  684.     dex
  685.     dex
  686.     bpl checkNextItem
  687.  
  688.     pha    ; space for result
  689.     PushWord #$4    ; reference is resource
  690.     PushLong #$0    ; no substitution strings currently
  691.     PushLong #BaseResID+2 ; alertString resource ID
  692.     _AlertWindow
  693.     pla    ; get the button number and dispose
  694.     bra finishUp
  695.     
  696. doRoutine    jsr (menuTable+2,x)    ; and call the routine
  697.     
  698. finishUp    PushWord #$0    ; Routine done - unhilite the menubar.
  699.     PushWord taskData+2 ; the menu number
  700.     _HiLiteMenu
  701.  
  702.     rts
  703.     
  704. ; Menu items that are ignored in this shell are included, but commented out.
  705.  
  706. menuTable
  707. ;    dc.W UndoID,  doUndo
  708. ;    dc.W CutID,   doCut
  709. ;    dc.W CopyID,  doCopy
  710. ;    dc.W PasteID, doPaste
  711. ;    dc.W ClearID, doClear
  712. ;    dc.W CloseID, doClose ; close handled by TaskMaster
  713.     dc.W AboutID, doAbout ; show about dialog
  714.     dc.W QuitID,  doQuit  ; set Done flag
  715. endMenuTable    
  716.  
  717.     ENDP
  718.  
  719.     EJECT
  720. *******************************************************************************
  721. *
  722. doAbout    PROC
  723. *
  724. * Description:    Bring up an Alert Dialog box with our about message in it.
  725. *
  726. * Inputs:    NONE
  727. * Outputs:    NONE
  728. * External Refs:    NONE
  729. * Entry Points:    NONE
  730. *
  731.     with Globals
  732.  
  733.     pha    ; space for result
  734.     PushWord #$4    ; reference is resource
  735.     PushLong #$0    ; no substitution strings currently
  736.     PushLong #BaseResID+1
  737.         ; alertString resource ID
  738.     _AlertWindow
  739.     pla    ; get the button number and dispose
  740.  
  741.     rts
  742.     ENDP
  743.  
  744.     EJECT
  745. *******************************************************************************
  746. *
  747. doQuit    PROC
  748. *
  749. * Description:    Set the Done flag to true. This tells the Event loop to
  750. *    exit.
  751. *
  752. * Inputs:    NONE
  753. * Outputs:    Done set to $FFFF (true)
  754. * External Refs:    NONE
  755. * Entry Points:    NONE
  756. *
  757.     with Globals
  758.  
  759.     lda #$FFFF    ; load any non-zero value
  760.     sta Done    ; and save it in the Done
  761.     rts
  762.     ENDP
  763.  
  764.     END
  765.